package com.xyw.code.study20200812.study3;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * User: xuyiwei
 * Date: 2020/8/13
 * Time: 上午8:53
 * Email: 1328312923@qq.com
 * Description: No Description
 **/
@Slf4j
public class ThreadTest {
    public static void main(String[] args) {
        ThreadPoolExecutor executorService =  new ThreadPoolExecutor(1, 3,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(1));
        log.info("1:最大数量:{},活跃数量:{}",executorService.getPoolSize(),executorService.getActiveCount());

        MyRunnable myRunnable1 = new MyRunnable();
        executorService.submit(myRunnable1);
        MyRunnable myRunnable2 = new MyRunnable();
        executorService.submit(myRunnable2);
        MyRunnable myRunnable3 = new MyRunnable();
        executorService.submit(myRunnable3);
        log.info("2:最大数量:{},活跃数量:{}",executorService.getPoolSize(),executorService.getActiveCount());

        log.info("3:最大数量:{},活跃数量:{}",executorService.getPoolSize(),executorService.getActiveCount());
    }
}

class MyRunnable implements Runnable{

//    @Override
//    public String call() throws Exception {
//        System.out.println("线程执行开始"+Thread.currentThread().getName());
//        Thread.sleep(10000);
//        System.out.println("线程执行结束"+Thread.currentThread().getName());
//        return null;
//    }

    @Override
    public void run() {
        System.out.println("线程执行开始"+Thread.currentThread().getName());
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程执行结束"+Thread.currentThread().getName());
    }
}